package com.ruoyi.project.digital.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.digital.domain.Pet;
import com.ruoyi.project.digital.service.IPetService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 宠物信息Controller
 *
 * @author ruoyi
 * @date 2023-10-28
 */
@RestController
@RequestMapping("/digital/pet")
public class PetController extends BaseController
{
    @Autowired
    private IPetService petService;

    /**
     * 查询宠物信息列表
     */
    @PreAuthorize("@ss.hasPermi('digital:pet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pet pet)
    {
        startPage();
        List<Pet> list = petService.selectPetList(pet);
        return getDataTable(list);
    }
    @GetMapping("/listall")
    public AjaxResult listall(Pet pet)
    {

        List<Pet> list = petService.selectPetList(pet);
        return AjaxResult.success(list);
    }
    /**
     * 导出宠物信息列表
     */
    @PreAuthorize("@ss.hasPermi('digital:pet:export')")
    @Log(title = "宠物信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Pet pet)
    {
        List<Pet> list = petService.selectPetList(pet);
        ExcelUtil<Pet> util = new ExcelUtil<Pet>(Pet.class);
        return util.exportExcel(list, "pet");
    }

    /**
     * 获取宠物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('digital:pet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(petService.selectPetById(id));
    }


    @GetMapping(value = "goCreatModel/{id}")
    public AjaxResult goCreatModel(@PathVariable("id") Long id)
    {
        petService.goCreatModel(id);
        return AjaxResult.success();
    }
    /**
     * 新增宠物信息
     */
    @PreAuthorize("@ss.hasPermi('digital:pet:add')")
    @Log(title = "宠物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Pet pet)
    {
        return toAjax(petService.insertPet(pet));
    }

    /**
     * 修改宠物信息
     */
    @PreAuthorize("@ss.hasPermi('digital:pet:edit')")
    @Log(title = "宠物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Pet pet)
    {
        return toAjax(petService.updatePet(pet));
    }

    /**
     * 删除宠物信息
     */
    @PreAuthorize("@ss.hasPermi('digital:pet:remove')")
    @Log(title = "宠物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petService.deletePetByIds(ids));
    }
}
